home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Mac-Source 1994 July
/
Mac-Source_July_1994.iso
/
C and C++
/
Libraries
/
usr (gcc 1.37 libs)
/
mac
/
open.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-12-08
|
2KB
|
75 lines
#include <sys/types.h>
#include <sys/syslimits.h>
#include <fcntl.h>
#include "crtlocal.h"
int chown(const char *name, uid_t owner, gid_t group)
{
OSErr err;
HFileParam pb;
pb.ioNamePtr = cnv_unix_name(name);
pb.ioVRefNum = crt_ioVRefNum;
pb.ioDirID = 0;
pb.ioFlCrDat = 0;
pb.ioFlMdDat = 0;
err = PBHGetFInfoSync((HParmBlkPtr) &pb );
if (!err)
{
pb.ioFlFndrInfo.fdCreator = owner;
pb.ioFlFndrInfo.fdType = group;
err = PBHSetFInfoSync((HParmBlkPtr) &pb );
}
return err?-1:0;
}
int open(const char *name, int flags, ...)
{
OSErr err;
IOParam pb;
int fd,refnum;
mysleep(1);
if (flags & O_CREAT)
{
unlink(name);
pb.ioNamePtr = cnv_unix_name(name);
pb.ioVRefNum = crt_ioVRefNum;
pb.ioVersNum = 0;
err = PBCreateSync((ParmBlkPtr) &pb);
if (!err) chown(name, 'CPED', 'TEXT');
}
pb.ioNamePtr = cnv_unix_name(name);
pb.ioVRefNum = crt_ioVRefNum;
pb.ioVersNum = 0;
pb.ioPermssn = flags&(O_WRONLY|O_RDWR)?fsRdWrPerm:fsRdPerm;
pb.ioMisc = 0;
if (flags&O_RESOURCE)
err = PBOpenRFSync((ParmBlkPtr) &pb);
else
err = PBOpenSync((ParmBlkPtr) &pb);
if ( err ) return -1;
refnum = pb.ioRefNum;
if (flags & O_APPEND)
{
pb.ioRefNum = refnum;
pb.ioPosMode = fsFromLEOF;
pb.ioPosOffset = 0;
(void)PBSetFPosSync((ParmBlkPtr)&pb);
}
if (flags & O_TRUNC)
{
pb.ioCompletion = 0;
pb.ioRefNum = refnum;
pb.ioMisc = 0;
PBSetEOFSync((ParmBlkPtr)&pb);
}
fd = next_fd(3);
crt_fd_tab[fd].fd = refnum;
crt_fd_tab[fd].flags = flags;
return fd;
}
int creat(const char *name, mode_t mode)
{
return open(name, O_CREAT|O_TRUNC|O_WRONLY, mode);
}